//
//  DULanguage.m
//  APP
//
//  Created by duyujin1 on 2021/9/6.
//

#import "DULanguage.h"
#import "NSBundle+Language.h"

static NSString *const DULanguageKey = @"DULanguageKey";
#define STANDARD_USER_DEFAULT  [NSUserDefaults standardUserDefaults]

@implementation DULanguage

//属性的set方法
+ (void)setUserLanguage:(NSString *)userLanguage {
    //跟随手机系统
    if (userLanguage.length == 0) {
        [self resetSystemLanguage];
        return;
    }
    //用户自定义
    [STANDARD_USER_DEFAULT setValue:userLanguage forKey:DULanguageKey];
    [STANDARD_USER_DEFAULT setValue:@[userLanguage] forKey:@"AppleLanguages"];
    [STANDARD_USER_DEFAULT synchronize];
}
//属性的get方法
+ (NSString *)userLanguage {
    return [STANDARD_USER_DEFAULT valueForKey:DULanguageKey];
}

//** 重置系统语言 */
+ (void)resetSystemLanguage {
    [STANDARD_USER_DEFAULT removeObjectForKey:DULanguageKey];
    [STANDARD_USER_DEFAULT setValue:nil forKey:@"AppleLanguages"];
    [STANDARD_USER_DEFAULT synchronize];
}

@end
